Uec3.AddOutSaleOrderButton = Ext.extend(AddSaleOrderButton, {
	loadBtnsUrl : RES_PATH + '/saleOrder/loadNotOnlineBtns.do',
	loadSaleOrderUrl : RES_PATH + '/saleOrder/loadNotOnlineSaleOrder.do'
});

Uec3.AddOutSaleOrderWindow = Ext.extend(AddSaleOrderWindow, {
	buttonModule : Uec3.AddOutSaleOrderButton,
	loadDetailsUrl : RES_PATH + '/saleOrder/loadNotOnlineDetails.do',
	initShowUrl : RES_PATH + '/saleOrder/notOnlineToShow.do',
	myWorkFlowId : 3,
	createDelPurBtn : function(value, metadata, record, rowIndex, colIndex, store) {
		
		if(this.status && this.status != '-1' && this.status != '0') {
			return '已确认';
		} 

		var delStr = '<a style="font-size:12px;" ' + ' href=javascript:getRunningWindow(' + 
				this.creatorIndex + ',Uec3.AddOutSaleOrderWindowCreator).delSaleRecordRow("' + 
				record.id + '"); >删除</a>';
				
		var showInventoryStr = '<a style="font-size:12px;" ' + ' href=javascript:getRunningWindow(' + 
				this.creatorIndex + ',Uec3.AddOutSaleOrderWindowCreator).showInventoryById("' + 
				record.data.partId + '"); >查看库存</a>';
				
		return delStr + '&nbsp;&nbsp;' + showInventoryStr;
	},
	createSaleItemGrid : function() {
			
		/*function submitForm() {
	  	   //取得表单数据	  	 	  
	       if(!sale_detailForm.getForm().isValid()){
	          return;
	       }
	       
	       if((sale_detailForm.getForm().findField("orderQuantity").getValue()+'').trim() == '') {
	       		Ext.MessageBox.alert("提示", "销售数量不能为空.");
	       		return;
	       }
	       
	       sale_detailForm.enable();	    
	       var  fmValue = sale_detailForm.getForm().getValues();
	       
//	       var code_index = this.sale_item_store.findExact('code', newRecord.code);
//	       var source_index = this.sale_item_store.findExact('source', newRecord.source);
//	       if(code_index != -1 && source_index != -1) {
//	          Ext.Msg.alert('提示', '对不起,该行记录已经存在了..');
//	          return;
//	       } 
	       
	       var validateExist = false;
	       Ext.each(this.sale_item_store.getRange(), function(rec) {
	       		if(rec.data.code + '&' + rec.data.source + '' == fmValue.code + '&' + fmValue.source + '') {
	       			validateExist = true;
	       			return false;
	       		}
	       });
	       
	       if( !validateExist ) {
	          //增加明细
	       	  this.sale_item_store.add(new this.sale_item_record(fmValue));	       	  
              this.sale_item_grid.getSelectionModel().selectFirstRow();
  	          sale_detailForm.form.el.dom.reset(); 
  	          sale_detailForm.enable();
  	          sale_detailForm.getForm().findField("code").focus();
	       } else {
	       		Ext.Msg.alert('提示', '对不起,该行记录已经存在了..');
	       }
	       
	   }
	   
	   function resetForm() {
  	        sale_detailForm.form.reset(); 
  	        sale_detailForm.enable();
  	        sale_detailForm.getForm().findField("code").focus();

//	  	    var columns = this.sale_item_grid.getColumnModel().columns;
//	        Ext.each(columns, function(value,index,arr) {
//	             var cellName = value.dataIndex;
//	             var field = sale_detailForm.form.findField(cellName);
//				 if(!field.isDisable){
//				    field.el.dom.value = '';
//				 }		             
//	        });
	  }
		
		var ds_code_select = new Ext.data.JsonStore({
			url : RES_PATH + '/part/queryOwnerCompPartProperties.do',
			root:'root',
			totalProperty:'totalProperty',
		    fields:[{name:'code',type:'string'}]
		});
		
		
		var sale_detailForm = new Ext.form.FormPanel({
			labelSeparator : "：",
			frame:true,
			border:false,
			defaults:{width:246},
			labelWidth:60,
			manager:Uec3.App.getDesktop().windows,
			items:[
			    {  
				    xtype:'combo',
				    //id:'code_detaiForm',
					//width :200,
					allowBlank : false,
					blankText : '零件编码不能为空',
					name : 'code',					
					fieldLabel:'零件编码',
					valueField:'code',
	                displayField : 'code',
   	  				mode : 'remote',
   	  				queryParam :'queryParam',
   	  				queryDelay:500,
   	  				minChars :2,
   	  				store : ds_code_select,
   	  				tpl: resultTpl,
   	  				itemSelector: 'div.search-item',
   	  				pageSize:10,
	   				selectOnFocus : true,
	   				triggerAction : 'all',
	   				loadingText : '加载中...',	   				
	   				emptyText : '请输入零件编码',
	   				listeners :{
					   'select':function(){
					   	  var value = this.getValue();
					      this.ownerCt.getForm().el.dom.reset();
					      this.setValue(value);
					   },
					   'change' : function() {
					   		this.ownerCt.getForm().el.dom.reset();
					   		this.setValue(this.getValue());
					   }
					}
			    }, {
			        xtype:'combo',
				    //width : 200,				   
					//name : 'source',
					fieldLabel:'零件来源',
					valueField:'varIndex',
	                displayField : 'varName',
   	  				mode : 'remote',
	   				hiddenName:'source',
	   				value:'',
	   				store : this.sourceType_store,
	   				selectOnFocus : true,
	   				forceSelection  :true,
	   				editable:true,
	   				triggerAction : 'all',
	   				loadingText : '加载中...',	   				
	   				emptyText : '请选择零件来源',	   				
	   				listeners :{
					   'select':autoFillDetailForm
					}
			    }, {
			        xtype:'textfield',
				    //width : 200,
//					allowBlank : false,
//					blankText : '零件名称不能为空',
					name : 'name',
					fieldLabel:'零件名称',
					readOnly:true,
					style:{background:'#dddddd'}
			    }, {
			    	xtype:'textfield',				    
//					allowBlank : false,
//					blankText : '零件单位不能为空',
					name : 'measurementUnit',
					fieldLabel:'单位',
	   				readOnly:true,
	   				style:{background:'#dddddd'}
			    }, {
			    	xtype:'hidden',
			    	name : 'partId'
			    }, {
			    	xtype:'hidden',
			    	name : 'level1Id'
			    }, {
			    	xtype:'hidden',
			    	name : 'level1Name'
			    }, {
			    	xtype:'hidden',
			    	name : 'level2Name'
			    }, {
			        xtype:'textfield',
//					allowBlank : false,
					readOnly:true,
					name : 'carModel',
					fieldLabel:'车型',
					style:{background:'#dddddd'}
			    }, {
			        xtype:'textfield',
//					allowBlank : false,
					readOnly:true,
					name : 'brand',
					fieldLabel:'品牌',
					style:{background:'#dddddd'}
			    }, {
			        xtype:'textfield',
//					allowBlank : false,
					readOnly:true,
//					blankText : '产地不能为空',
					name : 'origin',
					fieldLabel:'产地',
					style:{background:'#dddddd'}
			    }, {
			        xtype:'numberfield',
//					allowBlank : false,
					name : 'price',
					fieldLabel:'销售价',
//					allowBlank: false,
	                allowNegative: false	               
			    }, {
			        xtype:'numberfield',
					name : 'orderQuantity',
					fieldLabel:'订购数量',					
	                allowNegative: false	               	                
			    }, {
			        xtype:'numberfield',
					name : 'quantity',
					fieldLabel:'实际数量',					
	                allowNegative: false	               	                
			    }
			],
			buttons:[
			     {
//			     	itemId:'commitButton',
			     	text:'提交',
			        handler:submitForm.createDelegate(this)
			     },{
//			     	itemId:'resetButton',
			     	text:'重置',
			        handler:resetForm.createDelegate(this)
			     },{
//			     	itemId:'closeButton',
			     	text:'关闭',
			     	handler:function(){
			     	    detail_wind.hide();
			     	}
			     }
			],
			buttonAlign:'center'
	    });
		
	    *//**
         * 根据零件code、source查找零件信息
         *//*	  
	    function autoFillDetailForm(){
	    	 var source = this.getValue();
	    	 var code = sale_detailForm.getForm().findField("code").getValue();
	    	 if(code){
	    	     Ext.Ajax.request({
	    	        url :Uec3.App.Constants.homeUrl+"/part/queryPart!getPartByCodeAndSource.do",
	                params :{queryParam:Ext.encode({code:code,source:source})},
	                method :"post",
	                callback :function(options,success,response){
	                     
	                },
	                success:function(response,options) {	                	 
	                	  var resp = Ext.decode(response.responseText);
	                	  if(resp) {
	                	     sale_detailForm.getForm().findField("partId").setValue(resp.id);
	                	     sale_detailForm.getForm().findField("name").setValue(resp.name);
	                	     sale_detailForm.getForm().findField("measurementUnit").setValue(resp.measurementUnit);
	                	     sale_detailForm.getForm().findField("brand").setValue(resp.brand);
	                	     sale_detailForm.getForm().findField("origin").setValue(resp.origin);
	                	     sale_detailForm.getForm().findField("carModel").setValue(resp.carModel);
	                	     sale_detailForm.getForm().findField("level1Id").setValue(resp.level1Id);
	                	     sale_detailForm.getForm().findField("level1Name").setValue(resp.level1Name);
	                	     sale_detailForm.getForm().findField("level2Name").setValue(resp.level2Name);
	                	     sale_detailForm.getForm().findField("price").focus();
	                	  } else {
	                	     Ext.MessageBox.alert("提示","此零件编码和来源无相关零件信息,请重试");
	                	     sale_detailForm.getForm().findField("source").el.dom.value='';
	                	     sale_detailForm.getForm().findField("partId").el.dom.value='';
	                	     sale_detailForm.getForm().findField("name").el.dom.value='';
	                	     sale_detailForm.getForm().findField("measurementUnit").el.dom.value='';
	                	     sale_detailForm.getForm().findField("brand").el.dom.value='';
	                	     sale_detailForm.getForm().findField("origin").el.dom.value='';
	                	     sale_detailForm.getForm().findField("carModel").el.dom.value='';
	                	     sale_detailForm.getForm().findField("level1Id").el.dom.value='';
	                	     sale_detailForm.getForm().findField("level1Name").el.dom.value='';
	                	     sale_detailForm.getForm().findField("level2Name").el.dom.value='';
	                	     sale_detailForm.getForm().findField("orderQuantity").el.dom.value='';
	                	     sale_detailForm.getForm().findField("quantity").el.dom.value='';
	                	  }					       
	                },
	                failure:function(response,options){
	                      Ext.MessageBox.alert("提示","数据加载异常");
	                }
	    	   });	    		    	 
	       }else{
	         Ext.MessageBox.alert("提示","请填写零件编码");
	       }	    		         
	    }
	    
		//创建弹出窗口
		var detail_wind = new Ext.Window({
			layout:'fit',
		    width:380,
		    closeAction:'hide',
		    height:400,
			resizable :true,
			shadow : true,
			modal :true,
		    closable:true,
		    bodyStyle:'padding:5 5 5 5',
		    animCollapse:true,
			items:[sale_detailForm]
		});
		
		function addDetailData() {
			if(this.partner_combox.getValue() == null || (this.partner_combox.getValue()+'').trim() == '') {
				Ext.Msg.alert(PurChaseAlert.PROMOTE_ERROR, '对不起,您还没有选择采购单位..');
				return;
			}
			detail_wind.setTitle("新增订单明细");
			detail_wind.get(0).getForm().reset();
	        detail_wind.show();
		}*/
		
		//创建工具栏组件
		this.saleOrder_toolbar = 
		
//		this.status == '3' ? new Ext.Toolbar({
//			  items:[
//				{text : '[生成出库单]', iconCls : 'icon-add', handler : this.createSales.createDelegate(this)}
//			   ]
//			}) : 
			new Ext.Toolbar({
			  items:[
				{text : '[新增明细]', iconCls : 'icon-add', handler : this.addDetailData.createDelegate(this)},
				{text : '[删除全部]', iconCls : 'icon-del', handler : this.delAllRecords.createDelegate(this)}
			   ]
			});
		
		// 创建grid，装载明细数据
		return new Ext.grid.EditorGridPanel({
			style : {padding : '2px'},
			flex:1,
			clicksToEdit : 1,
			colModel : this.sale_item_colName,
			tbar : this.saleOrder_toolbar,
			store : this.sale_item_store,
			selModel : new Ext.grid.RowSelectionModel(
	                     {
	                        moveEditorOnEnter : true,
	                        singleSelect : true
	                     }
	        )
		});
	},
	addDetailData : function() {
		if(this.partner_combox.getValue() == null || (this.partner_combox.getValue()+'').trim() == '') {
			Ext.Msg.alert(PurChaseAlert.PROMOTE_ERROR, '对不起,您还没有选择采购单位..');
			return;
		}
		this.creator.app.getDesktop().launchWindowByParam('salePartPropSearchWindowCreator', 
			{'saleGrid' : this.sale_item_grid, 'saleRecord' : this.sale_item_record, 'partnerId' : this.partner_combox.getValue()});
	},
	delAllRecords : function() {
		this.sale_item_store.removeAll();
	}
});

Uec3.AddOutSaleOrderWindowCreator = Ext.extend(AddSaleOrderWindowCreator, {
	id : 'addOutSaleOrderWindowCreator',
	ordersName : '非在线销售订单',
	ordersNameEn : 'not_online_sale_order',
	getTypeWindow : function() {
		return Uec3.AddOutSaleOrderWindow;
	}
	
});